#! /usr/bin/env/python3
# coding:UTF-8
'''
    名称：掷骰子
    作者：王楠
    版本: 2.0
    日期：2020/03/01
    功能：dice_num，几个骰子
'''
import random


class Dices():
    def __init__(self, dice_num):
        self.dice_num = dice_num

    def roll_dice(self):
        num = random.randint(self.dice_num, 6 * self.dice_num)
        return num


def dice_main():
    '''自己写：
    nums = []
    roll_times = int(input('请输入投掷次数：'))
    dice_num = int(input('请输入骰子个数：'))
    result_list_times = [0] * (6 * dice_num - dice_num + 1)
    # result_list_num = list(range(dice_num, 6 * dice_num + 1))
    # result_dict = dict(zip(result_list_num, result_list_times))
    dice = Dice(dice_num)
    for i in range(roll_times):
        num = dice.roll_dice()
        nums.append(num)
        for x in range(dice_num, 6 * dice_num + 1):
            if num == x:
                result_list[x-dice_num] += 1
    print(nums)
    print('{}个骰子，投掷了{}次：'.format(dice_num, roll_times))
    for i, result in enumerate(result_list):
        print('{}出现了{}次,频率是{}%'.format(
            i + dice_num, result,
            result / roll_times * 100))
    '''
    nums = []
    roll_times = int(input('请输入投掷次数：'))
    dice_num = int(input('请输入骰子个数：'))
    result_list_times = [0] * (6 * dice_num - dice_num + 1)
    result_list_num = list(range(dice_num, 6 * dice_num + 1))
    result_dict = dict(zip(result_list_num, result_list_times))
    dice = Dices(dice_num)
    for i in range(roll_times):
        num = dice.roll_dice()
        nums.append(num)
        for x in result_list_num:
            if num == x:
                result_dict[x] += 1
    print(nums)
    print('{}个骰子，投掷了{}次：'.format(dice_num, roll_times))
    for result_num in result_list_num:
        print('出现点数{0}的次数是{1}次,频率是{2:.1f}%'.format(
            result_num, result_dict[result_num],
            result_dict[result_num] / roll_times * 100))
    print('{}个骰子，投掷了{}次：'.format(dice_num, roll_times))
    for result_num, result_times in result_dict.items():
        print('出现点数{0}的次数是{1}次,频率是{2:.1f}%'.format(
            result_num, result_times,
            result_times / roll_times * 100))


if __name__ == '__main__':
    dice_main()
